﻿/**************************************************
 * 文 件 名：IDbHelper.cs
 * 版    本：V1.0
 * 创 建 人：杨书林
 * 日    期：2011-6-1
 * 说    明：各类DbHelper公共方法的接口类
 
 * 修 改 人：
 * 日    期：
 * 描    述：
 **************************************************/
using System.Data;

namespace Ysl.Data.DbHelper
{
    /// <summary>
    /// IDbHelper
    /// 各类DbHelper公共方法的接口类
    /// </summary>
    public interface IDbHelper
    {
        #region 开始/执行/回滚事务操作
        /// <summary>
        /// 开始事务操作
        /// </summary>
        void BeginTransaction();

        /// <summary>
        /// 执行事务操作
        /// </summary>
        void Commit();

        /// <summary>
        /// 回滚事务操作
        /// </summary>
        void Rollback();
        #endregion

        #region 组织参数及相关方法
        /// <summary>
        /// 根据参数名和值组织参数
        /// </summary>
        /// <param name="parameterName">参数名称</param>
        /// <param name="parameterValue">值</param>
        /// <returns>返回IDbDataParameter类型</returns>
        IDbDataParameter MakeInParameter(string parameterName, object parameterValue);

        /// <summary>
        /// 根据参数名和值组织参数
        /// </summary>
        /// <param name="parameterName">参数名称</param>
        /// <param name="dbType">参数类型</param>
        /// <param name="parameterValue">值</param>
        /// <returns>返回IDbDataParameter类型</returns>
        IDbDataParameter MakeInParameter(string parameterName, DbType dbType, object parameterValue);

        /// <summary>
        /// 根据参数名和值组织参数
        /// </summary>
        /// <param name="parameterName">参数名称</param>
        /// <param name="dbType">参数类型</param>
        /// <param name="size">类型长度</param>
        /// <param name="parameterValue">值</param>
        /// <returns>返回IDbDataParameter类型</returns>
        IDbDataParameter MakeInParameter(string parameterName, DbType dbType, int size, object parameterValue);

        /// <summary>
        /// 根据参数名和值组织参数
        /// </summary>
        /// <param name="parameterName">参数名称</param>
        /// <param name="dbType">参数类型</param>
        /// <param name="size">类型长度</param>
        /// <returns>返回IDbDataParameter类型</returns>
        IDbDataParameter MakeOutParameter(string parameterName, DbType dbType, int size);

        /// <summary>
        /// 根据参数名和值组织参数
        /// </summary>
        /// <param name="parameterName">参数名称</param>
        /// <param name="dbType">参数类型</param>
        /// <param name="size">类型长度</param>
        /// <returns>返回IDbDataParameter类型</returns>
        IDbDataParameter MakeReturnParameter(string parameterName, DbType dbType, int size);

        /// <summary>
        /// 根据参数名和值组织参数
        /// </summary>
        /// <param name="parameterName">参数名称</param>
        /// <param name="dbType">参数类型</param>
        /// <param name="size">类型长度</param>
        /// <param name="parameterDirection">参数的输入、输出类型</param>
        /// <param name="parameterValue">值</param>
        /// <returns>返回IDbDataParameter类型</returns>
        IDbDataParameter MakeParameter(string parameterName, DbType dbType, int size, ParameterDirection parameterDirection, object parameterValue);

        /// <summary>
        /// 根据参数名和值组织参数
        /// </summary>
        /// <param name="parameterNames">参数名称</param>
        /// <param name="parameterValues">值</param>
        /// <returns>返回IDbDataParameter[]类型</returns>
        IDbDataParameter[] MakeInParameters(string[] parameterNames, params object[] parameterValues);

        /// <summary>
        /// 根据存储过程和值组织参数
        /// </summary>
        /// <param name="procedureName">存储过程名称</param>
        /// <param name="parameterValues">值</param>
        /// <returns>返回IDbDataParameter[]类型</returns>
        IDbDataParameter[] MakeProcedureParameters(string procedureName, object[] parameterValues);

        /// <summary>
        /// 获取存储过程参数集（不包括返回值参数）
        /// </summary>
        /// <param name="procedureName">存储过程名称</param>
        /// <returns>返回IDbDataParameter[]类型</returns>
        IDbDataParameter[] GetProcedureParameters(string procedureName);

        /// <summary>
        /// 获取存储过程参数集
        /// </summary>
        /// <param name="procedureName">存储过程名称</param>
        /// <param name="includeReturnValueParameter">是否包含返回值参数（true表示包含，false表示不包含，默认为false）</param>
        /// <returns>返回IDbDataParameter[]类型</returns>
        IDbDataParameter[] GetProcedureParameters(string procedureName, bool includeReturnValueParameter);

        /// <summary>
        /// 为参数赋值
        /// </summary>
        /// <param name="dbParameters">参数</param>
        /// <param name="parameterValues">值</param>
        void AssignParameters(IDbDataParameter[] dbParameters, params object[] parameterValues);
        #endregion

        #region ExecuteNonQuery
        /// <summary>
        /// 对连接执行SQL语句并返回受影响的行数
        /// </summary>
        /// <param name="sqlText">SQL语句</param>
        /// <returns>返回受影响的行数</returns>
        int ExecuteNonQuerySql(string sqlText);

        /// <summary>
        /// 对连接执行SQL语句并返回受影响的行数
        /// </summary>
        /// <param name="sqlText">SQL语句</param>
        /// <param name="dbParameters">参数</param>
        /// <returns>返回受影响的行数</returns>
        int ExecuteNonQuerySql(string sqlText, params IDbDataParameter[] dbParameters);

        /// <summary>
        /// 对连接执行存储过程并返回受影响的行数
        /// </summary>
        /// <param name="procedureName">存储过程名称</param>
        /// <returns>返回受影响的行数</returns>
        int ExecuteNonQueryProcedure(string procedureName);

        /// <summary>
        /// 对连接执行存储过程并返回受影响的行数
        /// </summary>
        /// <param name="procedureName">存储过程名称</param>
        /// <param name="parameterValues">参数值</param>
        /// <returns>返回受影响的行数</returns>
        int ExecuteNonQueryProcedure(string procedureName, params object[] parameterValues);

        /// <summary>
        /// 对链接执行操作并返回受影响的行数
        /// </summary>
        /// <param name="commandType">命令字符串类型</param>
        /// <param name="commandText">命令字符串</param>
        /// <returns>返回受影响的行数</returns>
        int ExecuteNonQuery(CommandType commandType, string commandText);

        /// <summary>
        /// 对链接执行操作并返回受影响的行数
        /// </summary>
        /// <param name="commandType">命令字符串类型</param>
        /// <param name="commandText">命令字符串</param>
        /// <param name="dbParameters">参数</param>
        /// <returns>返回受影响的行数</returns>
        int ExecuteNonQuery(CommandType commandType, string commandText, params IDbDataParameter[] dbParameters);
        #endregion

        #region ExecuteFill
        /// <summary>
        /// 填充数据表
        /// </summary>
        /// <param name="sqlText">SQL语句</param>
        /// <returns>返回数据表</returns>
        DataTable ExecuteFillSql(string sqlText);

        /// <summary>
        /// 填充数据表
        /// </summary>
        /// <param name="sqlText">SQL语句</param>
        /// <param name="tableName">表名</param>
        /// <returns>返回数据表</returns>
        DataTable ExecuteFillSql(string sqlText, string tableName);

        /// <summary>
        /// 填充数据表
        /// </summary>
        /// <param name="sqlText">SQL语句</param>
        /// <param name="dbParameters">参数</param>
        /// <returns>返回数据表</returns>
        DataTable ExecuteFillSql(string sqlText, params IDbDataParameter[] dbParameters);

        /// <summary>
        /// 填充数据表
        /// </summary>
        /// <param name="sqlText">SQL语句</param>
        /// <param name="tableName">表名</param>
        /// <param name="dbParameters">参数</param>
        /// <returns>返回数据表</returns>
        DataTable ExecuteFillSql(string sqlText, string tableName, params IDbDataParameter[] dbParameters);

        /// <summary>
        /// 填充数据表
        /// </summary>
        /// <param name="procedureName">存储过程</param>
        /// <returns>返回数据表</returns>
        DataTable ExecuteFillProcedure(string procedureName);

        /// <summary>
        /// 填充数据表
        /// </summary>
        /// <param name="procedureName">存储过程</param>
        /// <param name="tableName">表名</param>
        /// <returns>返回数据表</returns>
        DataTable ExecuteFillProcedure(string procedureName, string tableName);

        /// <summary>
        /// 填充数据表
        /// </summary>
        /// <param name="procedureName">存储过程</param>
        /// <param name="parameterValues">参数值</param>
        /// <returns>返回数据表</returns>
        DataTable ExecuteFillProcedure(string procedureName, params object[] parameterValues);

        /// <summary>
        /// 填充数据表
        /// </summary>
        /// <param name="procedureName">存储过程</param>
        /// <param name="tableName">表名</param>
        /// <param name="parameterValues">参数值</param>
        /// <returns>返回数据表</returns>
        DataTable ExecuteFillProcedure(string procedureName, string tableName, params object[] parameterValues);

        /// <summary>
        /// 填充数据表
        /// </summary>
        /// <param name="commandType">命令字符串类型</param>
        /// <param name="commandText">命令字符串</param>
        /// <param name="dbParameters">参数</param>
        /// <returns>返回数据表</returns>
        DataTable ExecuteFill(CommandType commandType, string commandText, params IDbDataParameter[] dbParameters);

        /// <summary>
        /// 填充数据表
        /// </summary>
        /// <param name="commandType">命令字符串类型</param>
        /// <param name="commandText">命令字符串</param>
        /// <param name="tableName">表名</param>
        /// <param name="dbParameters">参数</param>
        /// <returns>返回数据表</returns>
        DataTable ExecuteFill(CommandType commandType, string commandText, string tableName, params IDbDataParameter[] dbParameters);


        /// <summary>
        /// 填充数据集
        /// </summary>
        /// <param name="dataSet">数据集</param>
        /// <param name="commandType">命令字符串类型</param>
        /// <param name="commandText">命令字符串</param>
        void ExecuteFill(DataSet dataSet, CommandType commandType, string commandText);

        /// <summary>
        /// 填充数据集
        /// </summary>
        /// <param name="dataSet">数据集</param>
        /// <param name="commandType">命令字符串类型</param>
        /// <param name="commandText">命令字符串</param>
        /// <param name="dbParameters">参数</param>
        void ExecuteFill(DataSet dataSet, CommandType commandType, string commandText, params IDbDataParameter[] dbParameters);

        /// <summary>
        /// 填充数据集
        /// </summary>
        /// <param name="dataSet">数据集</param>
        /// <param name="commandType">命令字符串类型</param>
        /// <param name="commandText">命令字符串</param>
        /// <param name="tableName">表名</param>
        /// <param name="dbParameters">参数</param>
        void ExecuteFill(DataSet dataSet, CommandType commandType, string commandText, string tableName, params IDbDataParameter[] dbParameters);
        #endregion

        #region ExecuteReader
        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="sqlText">SQL语句</param>
        /// <returns>返回IDataReader类型</returns>
        IDataReader ExecuteReaderSql(string sqlText);

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="sqlText">SQL语句</param>
        /// <param name="dbParameters">参数</param>
        /// <returns>返回IDataReader类型</returns>
        IDataReader ExecuteReaderSql(string sqlText, params IDbDataParameter[] dbParameters);

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="procedureName">存储过程名称</param>
        /// <returns>返回IDataReader类型</returns>
        IDataReader ExecuteReaderProcedure(string procedureName);

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="procedureName">存储过程名称</param>
        /// <param name="parameterValues">参数值</param>
        /// <returns>返回IDataReader类型</returns>
        IDataReader ExecuteReaderProcedure(string procedureName, params object[] parameterValues);

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="commandType">命令字符串类型</param>
        /// <param name="commandText">命令字符串</param>
        /// <returns>返回IDataReader类型</returns>
        IDataReader ExecuteReader(CommandType commandType, string commandText);

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="commandType">命令字符串类型</param>
        /// <param name="commandText">命令字符串</param>
        /// <param name="dbParameters">参数</param>
        /// <returns>返回IDataReader类型</returns>
        IDataReader ExecuteReader(CommandType commandType, string commandText, params IDbDataParameter[] dbParameters);
        #endregion

        #region ExecuteScalar
        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="sqlText">SQL语句</param>
        /// <returns>返回object类型</returns>
        object ExecuteScalarSql(string sqlText);

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="sqlText">SQL语句</param>
        /// <param name="dbParameters">参数</param>
        /// <returns>返回object类型</returns>
        object ExecuteScalarSql(string sqlText, params IDbDataParameter[] dbParameters);

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="procedureName">存储过程名称</param>
        /// <returns>返回object类型</returns>
        object ExecuteScalarProcedure(string procedureName);

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="procedureName">存储过程名称</param>
        /// <param name="parameterValues">参数值</param>
        /// <returns>返回object类型</returns>
        object ExecuteScalarProcedure(string procedureName, params object[] parameterValues);

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="commandType">命令字符串类型</param>
        /// <param name="commandText">命令字符串</param>
        /// <returns>返回object类型</returns>
        object ExecuteScalar(CommandType commandType, string commandText);

        /// <summary>
        /// 执行查询
        /// </summary>
        /// <param name="commandType">命令字符串类型</param>
        /// <param name="commandText">命令字符串</param>
        /// <param name="dbParameters">参数</param>
        /// <returns>返回object类型</returns>
        object ExecuteScalar(CommandType commandType, string commandText, params IDbDataParameter[] dbParameters);
        #endregion
    }
}
